const models = require('../models')

const BtbWarnModel = models.BtbWarn

/**
 * 基本
 */

exports.BtbWarnModel = BtbWarnModel

exports.newAndSave = function (data) {
  const BtbWarn = new BtbWarnModel(data)
  return BtbWarn.save()
}

exports.delete = function (query) {
  return BtbWarnModel.remove(query)
}

exports.batchDeleteByIds = function (ids) {
  return BtbWarnModel.remove({ _id: { $in: ids || [] } })
}

exports.update = function (query, data) {
  return BtbWarnModel.update(query, {
    $set: data
  })
}

exports.find = function (query, opt) {
  return BtbWarnModel.find(query, {}, opt)
}

exports.findWidthField = function (query, field, opt) {
  return BtbWarnModel.find(query, field || {}, opt)
}

exports.findOne = function (query) {
  return BtbWarnModel.findOne(query)
}

exports.findOneById = function (id) {
  return BtbWarnModel.findById(id)
}

exports.check = function (query, opt) {
  return BtbWarnModel.findOne(query, '_id', opt)
}

exports.count = function (query) {
  return BtbWarnModel.count(query)
}
